define(["jquery", "easy-admin"], function ($, ea) {

    var init = {
        table_elem: '#currentTable',
        table_render_id: 'currentTableRenderId',
        index_url: 'admin/activityVisitor/index?activity_id=' + window.activityId,
        export_url: 'admin/activityVisitor/export?activity_id=' + window.activityId,
    };

    var Controller = {

        index: function () {
            ea.table.render({
                init: init,
                toolbar: ['refresh', 'export'],
                cols: [[
                    {field: 'o.order_sn', title: '订单编号', hide: true},
                    {field: 'o.pay_no', title: '支付编号', hide: true},
                    {field: 'u.nickname', title: '昵称', hide: true},
                    {field: 'o.name', title: '姓名', hide: true},
                    {field: 'o.phone', title: '手机号', hide: true},
                    {field: 'ru.nickname', title: '直推人员昵称', hide: true},
                    {field: 'cu.nickname', title: '溯源员工昵称', hide: true},

                    {field: 'avatar_url', title: '头像', search: false, templet: ea.table.image},
                    {field: 'a', title: '会员信息',  width: 350, search: false, templet: function (d) {
                        var text  = "昵称：" + d.nickname + "<br />"
                            + "openid：" + d.openid + "<br />"
                        if (typeof d.order_info.name !== "undefined" && d.order_info.name !== null && d.order_info.name !== "") {
                            text = text + "姓名：" + d.order_info.name + "<br />";
                        }
                        if (typeof d.order_info.phone !== "undefined" && d.order_info.phone !== null && d.order_info.phone !== "") {
                            text = text + "手机号：" + d.order_info.phone + "<br />";
                        }
                        if (typeof d.order_info.customer_type !== "undefined" && d.order_info.customer_type !== null && d.order_info.customer_type !== "") {
                            text = text + "客户类型：" + d.order_info.customer_type;
                        }
                        return text;
                        }},
                    {title: '订单', width: 350, search: false, templet: function (d) {
                        return "订单编号：" + ((d.order_sn != null) ? d.order_sn : "") + "<br />"
                            + "支付编号：" + ((d.pay_no != null) ? d.pay_no : "") + "<br />"
                            + "支付金额：" + ((d.total_price != null) ? d.total_price : "") + "<br />"
                            + "支付状态：" + (d.order_status === 2 ? "已支付" : "未支付")
                    }},
                    {title: '统计', search: false, templet: function (d) {
                        return "推荐奖励：" + ((d.payment_disburse_amount != null) ? d.payment_disburse_amount : 0) + "<br />"
                            + "翻牌奖励：" + ((d.activity_prize_count != null) ? d.activity_prize_count : 0) + "<br />"
                            + "平台盲盒：" + ((d.platform_box_prize_count != null) ? d.platform_box_prize_count : 0)
                    }},
                    {title: '数据', width: 350, search: false, templet: function (d) {
                        return ((d.is_clerk_recom === 1) ? '<span class="layui-badge layui-bg-green">员工直推</span>' : '<span class="layui-badge layui-bg-blue">非直推</span>') + "<br />"
                            + "上级：" + ((d.recom_nickname != null) ? d.recom_nickname : "") + "<br />"
                            + "溯源员工：" + ((d.clerk_nickname != null) ? d.clerk_nickname : "") + "<br />"
                            + "参与时间：" + ((d.create_time != null) ? d.create_time : "")
                    }},
                    {width: 340, title: '操作', templet: '#buttonTpl'},
                ]],
            });

            ea.listen();
        },
        add: function () {
            ea.listen();
        },
        edit: function () {
            ea.listen();
        },
        relational: function () {
            ea.listen();
        },
    };
    return Controller;
});